<template>
	<view>
		<evan-form ref="form" :model="info" :hide-required-asterisk="hideRequiredAsterisk">
			<view class="cu-form-group">
				<evan-form-item label="姓名">
					<input class="form-input" v-model="info.name" placeholder-class="form-input-placeholder"
						placeholder="请输入姓名" />
				</evan-form-item>
			</view>
			<view class="cu-form-group">
				<evan-form-item label="身份证号">
					<input class="form-input" v-model="info.id" placeholder-class="form-input-placeholder"
						placeholder="请输入身份证号" />
				</evan-form-item>
			</view>
			<view class="cu-form-group">
				<evan-form-item label="手机号">
					<input class="form-input" v-model="info.id" placeholder="请输入手机号" />
				</evan-form-item>
			</view>
			<view class="cu-form-group">
				<view class="title">来源地</view>
				<picker @change="PickerChange" :value="index" :range="picker">
					<view class="picker">
						{{index>-1?picker[index]:'请选择'}}
					</view>
				</picker>
			</view>
			<view class="cu-form-group">
				<view class="title">抵密日期</view>
				<picker mode="date" :value="date" start="2015-09-01" end="2020-09-01" @change="DateChange">
					<view class="picker">
						{{date}}
					</view>
				</picker>
			</view>
			<view class="cu-form-group">
				<view class="title">乘坐交通工具</view>
				<picker @change="PickerVehicle" :value="vehicle" :range="VehiclePicker">
					<view class="picker">
						{{vehicle>-1?VehiclePicker[vehicle]:'请选择'}}
					</view>
				</picker>
			</view>
			<view class="cu-form-group" v-show="isShow">
				<view class="title">{{VehiclePicker[vehicle]}} {{VehiclePickers[vehicle]}}</view>
				<input placeholder="请输入" name="input"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">来密山目的</view>
				<picker @change="objective" :value="objectiveIndex" :range="objectivePicker">
					<view class="picker">
						{{objectiveIndex>-1?objectivePicker[objectiveIndex]:'请选择'}}
					</view>
				</picker>
			</view>
			<view class="cu-form-group" v-show="isOther">
				<view class="title">其他</view>
				<input placeholder="请输入" name="input"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">密山域内居住地址</view>
				<AddressPicker @change="change" :level="3">
					<view class="picker">
						{{planLocate}}
					</view>
				</AddressPicker>
			</view>
			<view class="cu-form-group">
				<view class="title">是否发热、咳嗽、乏力</view>
				<picker @change="YesOrNo" :value="YesOrNoIndex" :range="YesOrNoPicker">
					<view class="picker">
						{{YesOrNoIndex>-1?YesOrNoPicker[YesOrNoIndex]:'请选择'}}
					</view>
				</picker>
			</view>
			<view class="cu-form-group">
				<view class="title">14天内曾途径地</view>
				<input placeholder="请输入" name="input"></input>
			</view>
			<view class="cu-bar bg-white">
				<view class="action">
					身份证上传
				</view>
				<view class="action">
					{{imgList.length}}/1
				</view>
			</view>
			<view class="cu-form-group">
				<view class="grid col-4 grid-square flex-sub">
					<view class="bg-img" v-for="(item,index) in imgList" :key="index" @tap="ViewImage"
						:data-url="imgList[index]">
						<image :src="imgList[index]" mode="aspectFill"></image>
						<view class="cu-tag bg-red" @tap.stop="DelImg" :data-index="index">
							<text class='cuIcon-close'></text>
						</view>
					</view>
					<view class="solids" @tap="ChooseImage" v-if="imgList.length<4">
						<text class='cuIcon-cameraadd'></text>
					</view>
				</view>
			</view>
		</evan-form>
		<button class="cu-btn block bg-blue margin-tb-sm lg" type="">提交</button>
	</view>
</template>

<script>
	import AddressPicker from "@/components/lingdang-AddressPicker/AddressPicker.vue"
	export default {
		data() {
			return {
				hideRequiredAsterisk: true,
				info: {
					name: '',
					id: '',
					phoneNumber: ''
				},
				imgList: [],
				address: '', //来源地
				YesOrNoPicker: ['是', '否'],
				YesOrNoIndex: -1,
				planLocate: '请选择地址',
				isOther: false,
				objectivePicker: ['长期居住', '探亲访友', '出差旅游', '途径中转', '其他'],
				objectiveIndex: -1,
				isShow: false,
				VehiclePickers: ['车次', '航班号', '出发地'],
				VehiclePicker: ['火车', '飞机', '汽车'],
				vehicle: -1,
				date: '请选择',
				index: -1,
				picker: ['国内中高风险区所在省市', '国内低风险地区', '港澳台地区', '境外地区']
			}
		},
		components: {
			AddressPicker
		},
		watch: {
			'vehicle': {
				handler(newVal) {
					if (newVal === -1) {
						this.isShow = false
					} else {
						this.isShow = true
					}
				},
				immediate: true
			},
			'objectiveIndex': {
				handler(newVal) {
					if (newVal === '4') {
						this.isOther = true
					} else {
						this.isOther = false
					}
				},
				immediate: true
			},
		},
		methods: {
			ViewImage(e) {
				uni.previewImage({
					urls: this.imgList,
					current: e.currentTarget.dataset.url
				});
			},
			ChooseImage() {
				uni.chooseImage({
					count: 4, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: (res) => {
						if (this.imgList.length != 0) {
							this.imgList = this.imgList.concat(res.tempFilePaths)
						} else {
							this.imgList = res.tempFilePaths
						}
					}
				});
			},
			DelImg(e) {
				uni.showModal({
					content: '确定要删除吗？',
					cancelText: '取消',
					confirmText: '确定',
					success: res => {
						if (res.confirm) {
							this.imgList.splice(e.currentTarget.dataset.index, 1)
						}
					}
				})
			},
			YesOrNo(e) {
				this.YesOrNoIndex = e.detail.value
			},
			change(result) {
				this.planLocate = '';
				result.data.forEach((item, index) => {
					if (index === 0) {
						this.planLocate += item.name
					} else {
						this.planLocate += '-' + item.name
					}
				})
				let arr = this.planLocate.split('-')
			},
			objective(e) {
				this.objectiveIndex = e.detail.value
			},
			PickerVehicle(e) {
				this.vehicle = e.detail.value
			},
			DateChange(e) {
				this.date = e.detail.value
			},
			PickerChange(e) {
				this.index = e.detail.value
				this.address = this.picker[this.index]
			}
		}
	}
</script>
